#include "StdAfx.h"
#include "SDLSurface.h"

SDLSurface::SDLSurface(void)
{
	m_surface = NULL;
}

SDLSurface::~SDLSurface(void)
{
	SDL_FreeSurface(m_surface);
}

bool SDLSurface::LoadImage( char* file)
{
	if (m_surface!=NULL)
	{
		SDL_FreeSurface(m_surface);
	}
	SDL_Surface* temp = NULL;
	if ((temp=SDL_LoadBMP(file))==NULL)
	{
		return false;
	}
	m_surface = SDL_DisplayFormat(temp);
	SDL_FreeSurface(temp);
	return true;
}

bool SDLSurface::BitBlt( int x,int y,SDL_Surface* src )
{
	if (m_surface==NULL||src==NULL)
	{
		return false;
	}
	SDL_Rect desRect;
	desRect.x = x;
	desRect.y = y;
	SDL_BlitSurface(src,NULL,m_surface,&desRect);
	return true;
}

bool SDLSurface::BitBlt( int x,int y,SDL_Surface* src,int sx,int sy )
{
	if (m_surface==NULL||src==NULL)
	{
		return false;
	}
	SDL_Rect desRect;
	desRect.x = x;
	desRect.y = y;
	SDL_Rect srcRect;
	srcRect.x = sx;
	srcRect.y = sy;
	SDL_BlitSurface(src,&srcRect,m_surface,&desRect);
	return true;
}